<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/include/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title><%=system_name%> - 产品管理</title>
	<%@include file="/WEB-INF/jsp/include/meta.jsp"%>
	
	<link href="<%=basePath%>css/public.css" rel="stylesheet" type="text/css">
	<link href="<%=basePath%>css/index.css" rel="stylesheet" type="text/css">
	<link href="<%=basePath%>css/common.css" rel="stylesheet" type="text/css" />
	<script src="<%=basePath%>js/common.js" type="text/javascript"></script>
	
	<script type="text/javascript" src="js/pagebar.js"></script>
	<script type="text/javascript" src="fram/engine.js" ></script>
	<script type="text/javascript" src="fram/util.js" ></script>
	<script type="text/javascript" src="fram/interface/productService.js"></script>
</head>

<body oncontextmenu='return false'>

<%@include file="/WEB-INF/jsp/include/head.jsp"%>
    
<div class="wrap100">
	<!--left begin-->
    <div class="fl" >

		<iframe width="236" name="menuFrame" id="menuFrame" height="640" frameborder="0" scrolling="no" src="<%=basePath%>trade/productList"></iframe>        
    
    </div>
	<!--left end-->

	<!--right begin-->
    <div class="fl">
    
        <iframe width="968" id="actionFrame" name="actionFrame" height="640" frameborder="0" scrolling="no" src="<%=basePath%>trade/productRight"></iframe>    
    
    </div>
	<!--right end-->    
    
    <div id="win_temp" style="display:none">
			<div id="winCon_1"><iframe name="winDivFrame" id="winDivFrame" frameborder="0" scrolling="no" width="600" height="450"></iframe></div>
		</div>
	
		<!-- loading -->
  		<div id="loading" style="position:absolute;top:200px;left:350px;z-index:9998;text-align:center;color:#0099FF;display:none">
  			<img src="<%=basePath%>images/loading-1.gif" /><br/>处理中，请稍候...
  		</div>
  	<script src="<%=basePath%>js/win.js" type="text/javascript"></script>
    </div>
	<!--left end-->
	
</div>

<%@include file="/WEB-INF/jsp/include/bottom.jsp"%>

<script type="text/javascript">
function loading(f){
		if(f){
    		$("win_temp").style.display="none";
			$("loading").style.display="";
		}else{
			$("win_temp").style.display="block";
			$("loading").style.display="none";
		}		
}

//刷新页面
function refresh(){
	WIN.close();
	WIN.showpg();
	WIN.closepg();
	reload();
}

function addProduct(){
	loading(true);
	WIN.show('<font size=5>添加产品信息</font>',$('winCon_1'),{width:600,height:450});
	$("winDivFrame").src="<%=basePath%>trade/productEdit?action=add";
}

function modifyProduct(id){
	if(null==id||''==id){
		alert('请选择产品信息！');return;
	}
	WIN.show('修改产品信息',$('winCon_1'),{width:600,height:450});
	$("winDivFrame").src="<%=basePath%>trade/productEdit?action=modify&id="+id;
}
function editProduct(id){
	if(null==id||''==id){
		alert('请选择产品信息！');return;
	}
	WIN.show('修改产品信息',$('winCon_1'),{width:600,height:450});
	productService.getProductById(id,function(data){
		$('productId0').value=data.id;
		$('name0').value=data.name;
		$('productNo0').value=data.productNo;
		$('material0').value=data.material;
		$('customsCode0').value=data.customsCode;
		$('declarationElements0').value=data.declarationElements;
		$('taxTate0').value=data.taxTate;
		if(data.inspection){$N('inspection0')[0].checked=true;}else{$N('inspection0')[1].checked=true;}
		$('detail0').value=data.detail;
		$('remark0').value=data.remark;
	})
}

function delProduct(id){
	if(null==id||''==id){
		alert('请选择产品信息！');return;
	}
	if(confirm("删除产品信息，确定删除 ？")){
		WIN.showpg();
		productService.deleteProduct(id,{
			callback:function(f){WIN.closepg();alert("删除成功");reload();},
			exceptionHandler:function(message){WIN.closepg();alert("删除失败，请重试");},
			errorHander:function(err){}
		})
	}
}

function submitProduct(){
	var data={
			id:			$('productId0').value,
			name:		$('name0').value,
			productNo:  $('productNo0').value,
			material:   $('material0').value,
			customsCode:$('customsCode0').value,
			declarationElements:$('declarationElements0').value,
			taxTate:    $('taxTate0').value,				
			inspection: $N('inspection0')[0].checked,
			detail:	    $('detail0').value.trim(),
			remark:		$('remark0').value.trim()		
	}    
	if(''==data.name){alert('产品名称不能为空');return;}
	if(''==data.productNo){
		alert('货号不能为空');return;
	//}else{
////		submitProduct.data=data;		
	//	productService.existsProductNo(data.productNo,{
		//	callback:function(f){if(f){alert('此货号已经存在，请更改');}else{submit(submitProduct.data);}},
			//exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");reload();},
			//errorHander:function(err){}
		//})
	}else{
		submit(data);
	}
}
function submit(data){
	WIN.close();
	WIN.showpg();
	productService.editProduct(data,{
		callback:function(f){WIN.closepg();alert("操作成功");reload();},
		exceptionHandler:function(message){WIN.closepg();alert(message);alert("操作失败，请重试");},
		errorHander:function(err){}
	})
}

</script>
</body>
</html>

